<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}i茅后台管理系统{% endblock %}</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-icons.css') }}">
    <!-- <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}"> -->
    <!-- CSS 文件 -->
    <!-- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> -->

    <!-- JS 文件（放在 </body> 前） -->
    <!-- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> -->
    <style>
        .nav-item.active {
            color: #fff;
            background-color: rgba(255, 255, 255, 0.1);
            border-radius: 4px;
        }
    </style>
</head>

<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container">
            <a class="navbar-brand" href="{{ url_for('web.index') }}">后台管理系统</a>
            <!-- 添加汉堡菜单按钮 -->
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <!-- 左侧导航栏 -->
                <ul class="navbar-nav mr-auto">
                    {% if current_user.is_authenticated %}
                    <li class="nav-item {% if active_page == 'dashboard' %}active{% endif %}">
                        <a class="nav-link" href="{{ url_for('web.dashboard') }}">仪表盘</a>
                    </li>
                    {% if current_user.role == 'admin' %}
                    <li class="nav-item {% if active_page == 'users' %}active{% endif %}">
                        <a class="nav-link" href="{{ url_for('web.users') }}">用户管理</a>
                    </li>
                    <li class="nav-item {% if active_page == 'products' %}active{% endif %}">
                        <a class="nav-link" href="{{ url_for('web.products') }}">商品列表</a>
                    </li>
                    <li class="nav-item {% if active_page == 'imaotailog' %}active{% endif %}">
                        <a class="nav-link" href="{{ url_for('web.imaotailog') }}">预约日志</a>
                    </li>
                    <li class="nav-item {% if active_page == 'result' %}active{% endif %}">
                        <a class="nav-link" href="{{ url_for('web.result') }}">申购结果</a>
                    </li>
                    {% endif %}
                    {% endif %}
                </ul>
                <!-- 右侧导航栏 -->
                <ul class="navbar-nav ms-auto">
                    {% if current_user.is_authenticated %}
                    <li class="nav-item">
                        <span class="navbar-text">欢迎, {{ current_user.username }}</span>
                    </li>
                    <li class="nav-item {% if active_page == 'products' %}logout{% endif %}">
                        <a class="nav-link" href="{{ url_for('web.logout') }}">退出</a>
                    </li>
                    {% endif %}
                </ul>
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
        {% for category, message in messages %}
        <div class="alert alert-{{ category }} alert-dismissible fade show">
            {{ message }}
            <button type="button" class="close" data-dismiss="alert">
                <span>&times;</span>
            </button>
        </div>
        {% endfor %}
        {% endif %}
        {% endwith %}

        {% block content %}{% endblock %}
    </div>
    <script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
    <script src="{{ url_for('static', filename='js/popper.min.js') }}"></script>
    <script src="{{ url_for('static', filename='js/bootstrap.bundle.min.js') }}"></script>
    <script src="{{ url_for('static', filename='js/bootstrap.bundle.min.js') }}"></script>
    {% block scripts %}{% endblock %}
</body>

<script>
    // / 或者使用jQuery方式初始化
    // $('[data-bs-toggle="tooltip"]').tooltip();
    document.addEventListener('DOMContentLoaded', function () {
        if (typeof bootstrap !== 'undefined') {
            var tooltips = document.querySelectorAll('[data-bs-toggle="tooltip"]');
            tooltips.forEach(function (el) {
                new bootstrap.Tooltip(el);
            });
        }
    });
</script>

</html>